/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer 42. 连续子数组的最大和
 * @author: WXY
 * @create: 2022-12-18 10:30
 * @Version 1.0
 **/


public class Num042_maxSubArray {
    public static int maxSubArray(int[] nums) {
        if (nums.length == 0 || nums == null) {
            return 0;
        }
        int cur = 0;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
            cur += nums[i];
            max = Math.max(cur,max);
            cur = cur < 0 ? 0 : cur;
        }
        return max;
    }
}
